package com.lx.entity;

import com.lx.annotation.Note;

import java.util.Objects;
import java.util.function.Consumer;

public interface Functional {
    @FunctionalInterface
    public interface Function<T, R> {
        R apply(T t) throws Exception;

        default R run(T t){
            try {
                return apply(t);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    @FunctionalInterface
    public interface TFunction<T,U, R> {
        R apply(T t ,U u) throws Exception;

        default R run(T t,U u){
            try {
                return apply(t,u);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    @Note("无参函数")
    @FunctionalInterface
    public interface NoArgsFunc {
        void exec() throws Exception;

        default void run(){
            try {
                exec();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    @FunctionalInterface
    public interface Supplier<T> {
        T get() throws Exception;

        default T run(){
            try {
                return get();
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }

    @FunctionalInterface
    public interface Consumer<T> {
        void accept(T t) throws Exception;

        default void run(T t){
            try {
                accept(t);
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
    }
}